package com.cvs.controller;

import com.cvs.bean.Orders;
import com.cvs.bean.User;
import com.cvs.service.OrdersService;
import com.cvs.service.UserService;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletRequest;

@Controller
public class OrdersController {
    @Autowired
    private OrdersService ordersService;
    @Autowired
    private UserService userService;
    @RequestMapping("myOrder")
    public  String myOrder(int uid, Integer pageNum, Integer pageSize, Model model, HttpServletRequest request){
        if(null==pageNum||null==pageSize){
           pageNum=new Integer(1);
           pageSize=new Integer(3);
        }

   PageInfo<Orders> pageInfo= ordersService.findAll(uid,pageNum,pageSize,request.getParameter("types"));
   model.addAttribute("orders",pageInfo);
        User user =userService.findUserInfo(uid);
        model.addAttribute("user",user);
        return "myOrder";
    }
}
